package com.teach.controller;

import com.teach.entity.ResponseEntity;
import com.teach.service.LotteryService;
import com.teach.service.TbIntegrateService;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/lottery")
@Api(tags = "抽奖controller")
public class LotteryController {
    @Resource
    LotteryService lotteryService;
    @Resource
    TbIntegrateService tbIntegrateService;

    @GetMapping("/getWard")
    @ApiOperation("抽奖")
    public ResponseEntity getWard(HttpServletRequest request){
        //获取token
        String token = request.getHeader("token");
        if(StringUtils.isBlank(token)){
            return new ResponseEntity(null,500,"没有登录，请登录",false);
        }
        //登录了，解析token
        Claims claims = Jwts.parser().setSigningKey("huangyujie").parseClaimsJws(token).getBody();
        Integer userId=Integer.parseInt(claims.getId());
        return tbIntegrateService.getWard(userId);
    }
}
